The net.devmanuals.validators package contains the Validator classes used in the application.
Package net.devmanuals.validators
The net.devmanuals.validators package contains the Validator classes used in the application. The structure of the net.devmanuals.validators package and code of each class is given below :
AddQuestionForm.java
package net.devmanuals.validators; import org.hibernate.validator.constraints.NotEmpty; public class AddQuestionForm { private Long questionId; private Long languageId; @NotEmpty private String question; private Long rightOption; @NotEmpty private String option1; @NotEmpty private String option2; @NotEmpty private String option3; @NotEmpty private String option4; public void setQuestionId(Long questionId){ this.questionId = questionId; } public Long getQuestionId(){ return questionId; } public void setLanguageId(Long languageId) { this.languageId = languageId; } public Long getLanguageId() { return languageId; } public void setQuestion(String question){ this.question = question; } public String getQuestion(){ return question; } public void setRightOption(Long rightOption){ this.rightOption = rightOption; } public Long getRightOption() { return rightOption; } public void setOption1(String option1){ this.option1 = option1; } public String getOption1(){ return option1; } public void setOption2(String option2){ this.option2 = option2; } public String getOption2(){ return option2; } public void setOption3(String option3){ this.option3 = option3; } public String getOption3(){ return option3; } public void setOption4(String option4){ this.option4 = option4; } public String getOption4(){ return option4; } }
AddQuestionValidator.java
package net.devmanuals.validators; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import net.devmanuals.validators.AddQuestionForm; @Component("addQuestionValidator") public class AddQuestionValidator{ public boolean supports(Class<?> klass){ return AddQuestionForm.class.isAssignableFrom(klass); } public void validate(Object target, Errors errors){ AddQuestionForm addQuestionForm = (AddQuestionForm) target; if(addQuestionForm.getLanguageId()==-1){ errors.rejectValue("languageId","NotEmpty.addQuestionForm.languageId","Select Language."); } if(addQuestionForm.getRightOption()==null){ errors.rejectValue("rightOption","selectRightAnswer.addQuestionForm.rightOption","Select Right Answer."); } } }
AdminLoginValidator.java
package net.devmanuals.validators; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import net.devmanuals.model.Admin; import net.devmanuals.service.AdminService; @Component("adminLoginValidator") public class AdminLoginValidator { @Autowired private AdminService adminService; public boolean supports(Class<?> klass) { return Admin.class.isAssignableFrom(klass); } public void validate(Object target, Errors errors){ Admin admin = (Admin) target; if ((admin.getAdminEmail() != null) && (admin.getAdminEmail().length() > 0)){ admin.setAdminEmail(admin.getAdminEmail().trim()); List adminlist = adminService.validateLoginAdmin(admin.getAdminEmail(),admin.getPassword()); if ((adminlist != null) && (adminlist.size() > 0)) { }else { errors.rejectValue("adminEmail","notMatchEmailAndPassword.admin.adminEmail","Admin Email or Password you entered is incorrect."); } } } }
QuestionPaperCommand.java
package net.devmanuals.validators; public class QuestionPaperCommand { private Long questionId; private String languageName; private String question; private Long option1Id; private String option1; private Long option2Id; private String option2; private Long option3Id; private String option3; private Long option4Id; private String option4; private Long rightOption; private String rightAnswer; public void setQuestionId(Long questionId){ this.questionId = questionId; } public Long getQuestionId() { return questionId; } public void setLanguageName(String languageName){ this.languageName = languageName; } public String getLanguageName(){ return languageName; } public void setQuestion(String question){ this.question = question; } public String getQuestion(){ return question; } public void setOption1Id(Long option1Id){ this.option1Id = option1Id; } public Long getOption1Id() { return option1Id; } public void setOption1(String option1){ this.option1 = option1; } public String getOption1(){ return option1; } public void setOption2Id(Long option2Id){ this.option2Id = option2Id; } public Long getOption2Id() { return option2Id; } public void setOption2(String option2){ this.option2 = option2; } public String getOption2(){ return option2; } public void setOption3Id(Long option3Id){ this.option3Id = option3Id; } public Long getOption3Id() { return option3Id; } public void setOption3(String option3){ this.option3 = option3; } public String getOption3(){ return option3; } public void setOption4Id(Long option4Id){ this.option4Id = option4Id; } public Long getOption4Id() { return option4Id; } public void setOption4(String option4){ this.option4 = option4; } public String getOption4(){ return option4; } public void setRightOption(Long rightOption){ this.rightOption = rightOption; } public Long getRightOption(){ return rightOption; } public void setRightAnswer(String rightAnswer){ this.rightAnswer = rightAnswer; } public String getRightAnswer(){ return rightAnswer; } }
UserForm.java
package net.devmanuals.validators; import javax.validation.constraints.Size; import org.hibernate.validator.constraints.Email; import org.hibernate.validator.constraints.NotEmpty; public class UserForm{ private Long userId; @NotEmpty @Size(min=1,max=100) private String userName; @NotEmpty @Size(min=1,max=100) @Email private String userEmail; @NotEmpty @Size(min=6,max=20) private String password; private String confirmPassword; private String userGender; @Size(min=10,max=20) private String phoneNo; private String address; public void setUserId(Long userId){ this.userId=userId; } public Long getUserId(){ return userId; } public void setUserEmail(String userEmail) { this.userEmail = userEmail; } public String getUserEmail() { return userEmail; } public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return userName; } public void setPassword(String password){ this.password=password; } public String getPassword(){ return password; } public void setConfirmPassword(String confirmPassword){ this.confirmPassword=confirmPassword; } public String getConfirmPassword(){ return confirmPassword; } public void setUserGender(String userGender){ this.userGender=userGender; } public String getUserGender(){ return userGender; } public void setPhoneNo(String phoneNo){ this.phoneNo=phoneNo; } public String getPhoneNo(){ return phoneNo; } public void setAddress(String address){ this.address=address; } public String getAddress(){ return address; } }
UserLoginValidator.java
package net.devmanuals.validators; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.validation.ValidationUtils; import net.devmanuals.model.User; import net.devmanuals.service.UserService; import net.devmanuals.utils.Encryption; @Component("userLoginValidator") public class UserLoginValidator { @Autowired private UserService userService; public boolean supports(Class<?> klass) { return User.class.isAssignableFrom(klass); } public void validate(Object target, Errors errors) { User user = (User) target; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userEmail", "NotEmpty.user.userEmail", "User Email must not be Empty."); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "NotEmpty.user.password", "Password must not be Empty."); if ((user.getUserEmail() != null) && (user.getUserEmail().length() > 0)) { user.setUserEmail(user.getUserEmail().trim()); List userlist = userService.validateLoginUser(user.getUserEmail(),Encryption.encrypt(user.getPassword()) ); if ((userlist != null) && (userlist.size() > 0)) { } else { errors.rejectValue("userEmail", "notMatchEmailAndPassword.user.userEmail", "User Email or Password you entered is incorrect."); } } } }
UserRegistrationValidator.java
package net.devmanuals.validators; import java.util.regex.*; import java.util.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.validation.ValidationUtils; import net.devmanuals.service.UserService; import net.devmanuals.validators.UserForm; @Component("userRegistrationValidator") public class UserRegistrationValidator { @Autowired private UserService userService; public boolean supports(Class<?> klass) { return UserForm.class.isAssignableFrom(klass); } public void validate(Object target, Errors errors){ UserForm userForm = (UserForm) target; ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phoneNo","NotEmpty.userForm.phoneNo","phoneNo must not be Empty."); // check userEmail errors.....Start.............................. if((userForm.getUserEmail()).length()>0){ userForm.setUserEmail((userForm.getUserEmail().trim())); Pattern p=Pattern.compile(".+@.+\\.[a-z]+"); Matcher m=p.matcher(userForm.getUserEmail()); boolean b=m.matches(); if(b!=true){ errors.rejectValue("userEmail", "userEmail.is.not.valid", "User Email not a well-formed email address."); }else{ List userlist=userService.getUserByUserEmail(userForm.getUserEmail()); if(userlist!=null && userlist.size()>0){ errors.rejectValue("userEmail", "matchUserEmail.memberForm.userEmail", "User Email already exist."); } } } // check userEmail errors.....End............................. if((userForm.getUserGender()).equals("-1")){ errors.rejectValue("userGender", "select.userForm.userGender","Select Gender." ); } if(!(userForm.getPassword()).equals(userForm.getConfirmPassword())){ errors.rejectValue("password", "matchpassword.userForm.password","Password and Confirm Password do not match." ); } } }
[ 0 ] Comments